package com.bowen.spike.my_enum;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum Gender implements BaseEnum {

    MAN(0, "男"),
    WOMEN(1, "女");

    @JsonValue // 序列化指定字段
    @EnumValue //数据库序列化指定字段
    int value;
    String desc;


    // 反序列化指定方法
    @JsonCreator(mode = JsonCreator.Mode.DELEGATING)
    public static Gender of(Integer value) {
        for (Gender gender : values()) {
            if (gender.equalsValue(value)) {
                return gender;
            }
        }
        return null;
    }

}
